package com.lfy.aop;


import com.lfy.util.SpElUtils;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.aspectj.weaver.loadtime.definition.Definition;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.xml.crypto.dsig.SignatureMethod;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

@Aspect
@Component
@Slf4j
public class AA {

    @Pointcut("@annotation(com.lfy.aop.TT)")
    public void setLog(){

    }

    @Around("setLog()")
    public Object t(ProceedingJoinPoint point)  {
        System.out.println("aop");
        Method method = ((MethodSignature) point.getSignature()).getMethod();
        TT tt = method.getAnnotation(TT.class);
        if(tt.value().isEmpty()){
            System.out.println(method.getDeclaringClass()+"#"+method.getName());
        }else {
            String s = SpElUtils.parseSpEl(method, point.getArgs(), tt.value());
            System.out.println(s);
        }



        try {
            return point.proceed();
        } catch (Throwable e) {
            return "出错了";
        }
    }
}
